/*
-------------------------------------------------------------------
BIE is Copyright 2001-2004 Brunswick Corp.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/bie_license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------

*/
/*
 * HTTPPost.java
 *
 * Created on July 17, 2002, 4:46 PM
 */

package tests.jd;

import java.net.*;
import java.io.*;

/**
 *
 * @author  jdepons
 */
public class HTTPPost {
    
    /** Creates a new instance of HTTPPost */
    public HTTPPost() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception{
    
        Socket s = new Socket("wd-016", 5803);        
        OutputStream os = s.getOutputStream();
        
        boolean isRequest = false;
        String soap = "";
        String dest = "";
        if (isRequest) {
            dest = "Request?routeID=ftpTo12";                        
            soap +="<?xml version=\"1.0\" standalone=\"no\"?>";
            soap +="<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">";
            soap +="<SOAP-ENV:Body>";
            soap +="<m:OrderRequest xmlns:m=\"uri:IDS\">";
            soap +="<VendorCode>STG</VendorCode>";
            soap +="<UserName>JEFF</UserName>";
            soap +="<ShippingMethod>UPS</ShippingMethod>";
            soap +="<ShippingAddressCode></ShippingAddressCode>";
            soap +="<PaymentMethod>Invoice</PaymentMethod>";
            soap +="<PONumber>16535</PONumber>";
            soap +="<ClientId>Astra 0.0.0</ClientId>";
            soap +="<AccountNumber>0011234567</AccountNumber>";
            soap +="<Document>&lt;?xml version=\"1.0\" encoding=\"ISO-8859-1\"?&gt;&lt;OrderRequest&gt;&lt;LineItem Sku=\"96-1314\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"96-1314\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"96-1301\" QuantityRequested=\"2\"/&gt;&lt;LineItem Sku=\"38-8567\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"96-1323\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"66-8653\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"86-8275\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"88-8816\" QuantityRequested=\"10\"/&gt;&lt;LineItem Sku=\"86-8453\" QuantityRequested=\"2\"/&gt;&lt;LineItem Sku=\"89-8441\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"38-8635\" QuantityRequested=\"2\"/&gt;&lt;LineItem Sku=\"94-4106\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"14-8248\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"14-8945\" QuantityRequested=\"2\"/&gt;&lt;LineItem Sku=\"14-9014\" QuantityRequested=\"2\"/&gt;&lt;LineItem Sku=\"94-1152\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"55-8369\" QuantityRequested=\"3\"/&gt;&lt;LineItem Sku=\"55-9653\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"55-8076\" QuantityRequested=\"2\"/&gt;&lt;LineItem Sku=\"55-1731\" QuantityRequested=\"3\"/&gt;&lt;LineItem Sku=\"55-8535\" QuantityRequested=\"3\"/&gt;&lt;LineItem Sku=\"55-8522\" QuantityRequested=\"2\"/&gt;&lt;LineItem Sku=\"31-8899\" QuantityRequested=\"3\"/&gt;&lt;LineItem Sku=\"22-8345\" QuantityRequested=\"2\"/&gt;&lt;LineItem Sku=\"31-1570\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"31-8383\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"31-8396\" QuantityRequested=\"2\"/&gt;&lt;LineItem Sku=\"31-9044\" QuantityRequested=\"2\"/&gt;&lt;LineItem Sku=\"31-9015\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"38-8944\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"38-8991\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"80-8504\" QuantityRequested=\"2\"/&gt;&lt;LineItem Sku=\"83-8480\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"83-8650\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"96-9021\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"55-1708\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"55-8124\" QuantityRequested=\"3\"/&gt;&lt;LineItem Sku=\"55-9798\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"66-8652\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"66-8743\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"77-8602\" QuantityRequested=\"6\"/&gt;&lt;LineItem Sku=\"83-8153\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"88-1083\" QuantityRequested=\"20\"/&gt;&lt;LineItem Sku=\"92-8915\" QuantityRequested=\"2\"/&gt;&lt;LineItem Sku=\"94-4255\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"96-8444\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"98-9162\" QuantityRequested=\"1\"/&gt;&lt;LineItem Sku=\"88-8804\" QuantityRequested=\"20\"/&gt;&lt;/OrderRequest&gt;</Document>";
            soap +="</m:OrderRequest>";
            soap +="</SOAP-ENV:Body>";
            soap +="</SOAP-ENV:Envelope>";
            
        }else {    
            String mid = "m1028036575168";
            dest = "Response?routeID=ftpGet";            
            soap +="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>"; 
            soap +="<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">";
            soap +="<SOAP-ENV:Body>";
            soap +="<m:OrderReply xmlns:m=\"uri:IDS\">";
            soap +="<RequestId>" + mid + "</RequestId>";
            soap +="<ClientId>ASTRA_Linx_V306~IDS</ClientId>";
            soap +="<UserName>j.allen</UserName>";
            soap +="</m:OrderReply>";
            soap +="</SOAP-ENV:Body>";
            soap +="</SOAP-ENV:Envelope>";
                    
        }

        String str = "";
        str +="POST /ids/" + dest + " HTTP/1.1\n";
        str +="Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*\n";
        str +="Referer: http://localhost:81/post.html\n";
        str +="Accept-Language: en-us\n";
        str +="Content-Type: application/x-www-form-urlencoded\n";
        str +="Accept-Encoding: gzip, deflate\n";
        str +="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)\n";
        str +="Host: localhost:5803\n";
        str +="Content-Length: " + soap.length() + "\n";
        str +="Connection: Keep-Alive\n";
        str +="Cache-Control: no-cache\n";
        str +="\n";
        str += soap;        

        os.write(str.getBytes());         
        BufferedReader br= new BufferedReader(new InputStreamReader(s.getInputStream()));

        String line = "";
        
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }

        s.close();                           
    }
    
}
